#include "boxentity.hpp"
#include <sstream>
#include <cstdlib>

BoxEntity::BoxEntity(ximera::graphics::IWorld* graphics, ximera::physics::IWorld* physics)
{
    static int count = 0;
    std::wostringstream strm(L"object");
    strm << ++count;

    static Real ypos = 0;
    ypos += 40;

    Real xpos = std::rand() % 5;

    //_entity = graphics->createEntity(strm.str(), L"cube.mesh");
    _entity = graphics->createEntity(strm.str(), ximera::graphics::PrefabEntityType::Sphere);
    _entity->materialName(L"RustyBarrel");
    _node = graphics->rootNode()->createChild(strm.str());
    _node->attach(_entity);
    _node->position(math::Vector3(xpos, ypos, 0));
    _node->scale(0.1f, 0.1f, 0.1f);

    _body = physics->space()->createEntity();
    _body->body()->mass(5);
    _body->body()->position(math::Vector3(xpos, ypos, 0));    
    
    //physics::IBox* shape = _body->createShape<physics::IBox>();
    //shape->extents(math::Vector3(6.5f, 6.5f, 6.5f));

    physics::ISphere* shape = _body->createShape<physics::ISphere>();
    shape->radius(6);
}

void BoxEntity::update()
{
    _node->orientation(_body->body()->orientation());
    _node->position(_body->body()->position());
}
